<template>
  <view>
    <scroll-view class="scrollView" scroll-y enable-flex @scrolltolower="loadMore" :refresher-triggered="triggered">
      <view class="allContaienr" @click="clickCell(item)" v-for="(item, index) in list" :key="index">
        <view class="flexArea">
          <view class="itemName">{{ item.infoTitle }}</view>
          <view v-if="item.status == 'result'" class="red">{{ item.score }}分</view>
          <view v-else class="green">评定中</view>
        </view>
        <view class="itemText">共 {{ item.questionNum }} 个面试题</view>
        <view class="itemText">面试时间：{{getMdate(item.startTime)}}</view>
        <view class="flexArea">
          <view class="itemText">面试时长：{{ item.totalTimeStr }}</view>
          <view v-if="item.status == 'result'" class="itemText">查看 ></view>
        </view>
      </view>
      <u-loadmore
        v-if="list.length > 0 || !loaded"
        class="list-more"
        :status="moreLoading"
        :load-text="loadText"
      />
      <Empty
        v-if="loaded && list.length <= 0"
        :baseImg="emptyImg"
        text="暂无数据"
        :fontWeight="400"
      />
    </scroll-view>
  </view>
</template>

<script>
import common from '@/api/common.js';
import Empty from "@/components/Empty.vue";
import { reqZhituGetRecord } from "@/api/modules/company";
export default {
  components: {
    Empty
  },
  props: {
    updateCount: {
      type: Number,
      default: 0,
    },
  },

  watch: {
    updateCount(newValue, oldValue) {
      if (newValue) {
        this.getData(false);
      }
    },
  },

  data() {
    return {
      topHeight: getApp().globalData.topHeight,
      keyword: "",
      list: [],
      companyId: uni.getStorageSync("company-id"),
  
      pageParams: {
        pageNo: 1,
        pageSize: 10,
      },
      emptyImg: this.$imgBaseSelf + "common/empty.png",
      searchIcon: this.$imgBaseSelf + "common/search.png",
      finished: false,
      loading: false,
      moreLoading: "loadmore",
      loadText: {
        loadmore: "加载更多",
        loading: "加载中",
        nomore: "已经到底啦",
      },
      loaded: false,

      currentOption:{
        label: "按得分升序",
        value: 1,
        type: "score_asc",
      },
    };
  },
  mounted() {
    this.getData(false);
    this.$bus.$on('updateContentInterviewListAI', this.updateHandler)
  },
  methods: {
    updateHandler(date) {
      this.moreLoading = "loadmore";
      this.getData(false);
    },
    
    getMdate(date) {
      return common.getMinuteTime(date) 
    },
    loadMore() {
      this.getData(true);
    },
    onRestore() {
      this.triggered = false;
      this._triggered = false;
    },
    onRefresh() {
      if (this._triggered) return;
      this._triggered = true;

      if (!this.triggered) {
        this.triggered = true;
      }
      this.getData(false);
    },
    getData(isMore) {
      if (this.moreLoading == "loading") return;
      if (this.moreLoading == "nomore" && isMore) {
        return;
      }
      if (!isMore) {
        this.pageParams.pageNo = 1; // 刷新数据
      }
      let personId = uni.getStorageSync("person-id").slice(2) || undefined;
      if (!personId) {
        this.loaded = true;
        this.moreLoading = "nomore";
        return;
      }
      this.moreLoading = "loading";
      const params = {
        personId: personId,
        pageNo:this.pageParams.pageNo,
        pageSize:this.pageParams.pageSize,
        modelType:"zph"
      };
      reqZhituGetRecord(params).then((res) => {
          console.log("🚀 ~ reqZhituGetRecord ~ res:", res)
          this.moreLoading = "loadmore";
          this.loaded = true;
          if (res.code == 200) {
            if (isMore) {
              this.list.push(...res.data);
            } else {
              this.list = res.data;
            }
            this.pageParams.pageNo++;
            if (this.pageParams.pageNo > res.pageparam.pages) {
              this.moreLoading = "nomore";
            }
          } else {
            this.moreLoading = "nomore";
            uni.showToast({
              title: res.status_desc,
              icon: "none",
            });
          }
        })
        .catch((e) => {
          console.log(e);
          this.moreLoading = "nomore";
        })
        .finally(() => {
          this.triggered = false;
          this._triggered = false;
        });
    },
   
    clickCell(item) {
      if (item.status == "result") {
        uni.navigateTo({
          url: "/pagesSub/companyCenter/interviewAI/interviewResult?objId=" + item.id + "&from=zph"
        });
      }
    },
  },
};
</script>

<style lang="scss" scoped>
$img-base-cdetail: $img-base + "cdetail/";


.scrollView {
  box-sizing: border-box;
  height: calc(100vh - 580rpx);
}

.allContaienr {
  display: flex;
  background: white;
  border-radius: 32rpx;
  padding: 32rpx;
  margin: 32rpx;
  flex-direction: column;
  .flexArea {
    display: flex;
    justify-content: space-between;
  }

  .itemName {
    font-size: 16px;
    color: #222222;
  }
  .itemText {
    margin-top: 10rpx;
    font-size: 12px;
    color: #888888;
  }
  .itemTime {
    margin-top: 12rpx;
    font-size: 12px;
    color: #888888;
  }

  .itemResultNum {
    margin-top: 20rpx;
    font-size: 12px;
    color: #888888;
  }

  .itemContent {
    display: flex;
    flex-direction: column;
  }

  .red {
    color: #F75A3E;
    font-size:40rpx;
  }
  .green {
    color: #0EA105;
    font-size:40rpx;
  }
}


</style>
